import { ObjCreate } from "../common/ObjCreate";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../extend/language/Language";
import { SPublicMiniPlayer } from "../../../../Message/Public/SPublicMiniPlayer";
import { TeammateAvatar } from "../avatar/TeammateAvatar";
import { GButton } from "../../../../com/mui/controls/GButton";
import { TweenMax } from "../../../../com/greensock/TweenMax";
import { Quint } from "../../../../com/greensock/easing/Quint";
import { SEntityId } from "../../../../Message/Public/SEntityId";
import { EntityUtil } from "../../scene/layer/utils/EntityUtil";
import { SystemSetter } from "../system/SystemSetter";
//class TeamAvatarSprite
    
    export  class TeamAvatarSprite /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._teamAvatar = [];
            return;
        }

        /* internal  */createTeamAvatar(arg1: Array<any>): void
        {
            var loc2=null;
            var loc3=null;
            if (this._teamSprite == null) 
            {
                this._teamSprite = new Object /* flash.display.Sprite */();
                this._teamSprite.y = 10;
                this.addChild(this._teamSprite);
                this._isShow = true;
            }
            this._teamShowButton = ObjCreate.createGButton("", 0, 0, 21, 20, this);
            this._teamShowButton.styleName = "PrevPageButton";
            this._teamShowButton.toolTipData = HTMLUtil.addColor(Language.getString(51013), "#FFFFFF");
            this._teamShowButton.addEventListener(flash.events.MouseEvent.CLICK, this.onTeamShowButtonClickHandler);
            var loc1=0;
            while (loc1 < 4) 
            {
                loc2 = arg1[loc1] as SPublicMiniPlayer;
                (loc3 = new TeammateAvatar(loc2)).y = loc1 * 76;
                this._teamAvatar.push(loc3);
                this._teamSprite.addChild(loc3);
                ++loc1;
            }
            return;
        }

        /* internal  */onTeamShowButtonClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as GButton;
            if (loc1.styleName != "PrevPageButton") 
            {
                this.showTeamAvatar(true);
            }
            else 
            {
                this.showTeamAvatar(false);
            }
            return;
        }

        public showTeamAvatar(arg1: Boolean): void
        {
            this._isShow = arg1;
            if (arg1) 
            {
                TweenMax.to(this._teamSprite, 0.2, {"x": 0, "ease": Quint.easeOut});
                this._teamShowButton.width = 21;
                this._teamShowButton.height = 20;
                this._teamShowButton.styleName = "PrevPageButton";
                this._teamShowButton.toolTipData = HTMLUtil.addColor(Language.getString(51013), "#FFFFFF");
            }
            else 
            {
                TweenMax.to(this._teamSprite, 0.2, {"x":-200, "ease": Quint.easeOut});
                this._teamShowButton.width = 27;
                this._teamShowButton.height = 92;
                this._teamShowButton.styleName = "ShowTeamButton";
                this._teamShowButton.toolTipData = HTMLUtil.addColor(Language.getString(51019), "#FFFFFF");
            }
            return;
        }

        public updateTeamAvatar(arg1: Array<any>): void
        {
            var loc2=0;
            var loc3=null;
            var loc4=null;
            var loc1=arg1.length;
            if (this._isFirstAdd) 
            {
                this.createTeamAvatar(arg1);
                this._isFirstAdd = false;
            }
            else 
            {
                loc2 = 0;
                while (loc2 < 4) 
                {
                    loc3 = arg1[loc2] as SPublicMiniPlayer;
                    if (loc4 = this._teamAvatar[loc2] as TeammateAvatar) 
                    {
                        if (loc2 < loc1) 
                        {
                            loc4.updateByPublicMiniPlayer(loc3);
                            if (loc4.parent != this._teamSprite) 
                            {
                                this._teamSprite.addChild(loc4);
                            }
                        }
                        else if (loc4.parent == this._teamSprite) 
                        {
                            this._teamSprite.removeChild(loc4);
                        }
                    }
                    ++loc2;
                }
            }
            if (loc1 < 1) 
            {
                if (this._teamShowButton && this._teamShowButton.parent == this) 
                {
                    this.removeChild(this._teamShowButton);
                }
            }
            else if (this._teamShowButton && this._teamShowButton.parent == null) 
            {
                this.addChild(this._teamShowButton);
            }
            return;
        }

        /* internal  */getTeamAvatar(arg1: SEntityId): TeammateAvatar
        {
            var loc1=null;
            var loc2=0;
            var loc3=this._teamAvatar;
            for(loc1 of loc3) 
            {
                if (!loc1.selfSEntityId) 
                {
                    continue;
                }
                if (!EntityUtil.equal(loc1.selfSEntityId, arg1)) 
                {
                    continue;
                }
                return loc1;
            }
            return null;
        }

        public teamTalk(arg1: SEntityId, arg2: string, arg3: string=""): void
        {
            if (this._isShow == false || SystemSetter.currentSetter.hideTeamChatBubble) 
            {
                return;
            }
            var loc1;
            if (loc1 = this.getTeamAvatar(arg1)) 
            {
                loc1.talk(arg2, arg3);
            }
            return;
        }

        /* internal */ /* var */_teamShowButton: GButton;

        /* internal */ /* var */_isFirstAdd: Boolean=true;

        /* internal */ /* var */_teamSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_isShow: Boolean=false;

        /* internal */ /* var */_teamAvatar: Array<any>;

        /* internal */ static /* var */_instance: TeamAvatarSprite;
    }
